package com.zxj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seventh.common.pojo.R;
import com.zxj.mapper.CarCommentMapper;
import com.zxj.pojo.entity.TbCar;
import com.zxj.pojo.entity.TbCarComment;
//import com.zxj.pojo.vo.CommentVo;
import com.zxj.pojo.vo.CommentVo;
import com.zxj.service.CarCommentService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @program: clms-seventh
 * @description:
 * @author: 张修杰
 * @create: 2021-07-24 22:04
 **/
@Service
public class CarCommentServiceImpl implements CarCommentService {
    @Resource
    CarCommentMapper carCommentMapper;
    @Override
    public R findAllCarCommentPage(Integer currentPage, Integer pageSize, CommentVo commentVo) {
        QueryWrapper<TbCarComment> wrapper=new QueryWrapper<>();

        if (StringUtils.isNotEmpty(commentVo.getName())){
            wrapper.like("username",commentVo.getName());
        }
        Page<TbCarComment> page=new Page<>(currentPage,pageSize);
        IPage<TbCarComment> page1=carCommentMapper.CarCommentList(page,wrapper);
        //carMapper.selectPage(page,wrapper);
        return R.ok().put("records",page1.getRecords()).put("total",page1.getTotal());

    }

    @Override
    public R updateCarCommentById(TbCarComment tbCarComment) {
        int i= carCommentMapper.updateById(tbCarComment);
        return (i>0)? R.ok():R.error();
    }

    @Override
    public R selectCarCommentById(String id) {
        TbCarComment tbCarComment=carCommentMapper.selectById(id);
        return R.ok().put("tbCarComment",tbCarComment);
    }

    @Override
    public R insertCarComment(TbCarComment tbCarComment) {
        int i= carCommentMapper.insert(tbCarComment);
        return (i>0)?R.ok():R.error();
    }

    @Override
    public R deleteCarComment(String id) {
        int i=carCommentMapper.deleteById(id);
        return (i>0)?R.ok():R.error();
    }
}
